package com.admin.business.venusProjectServiceComment;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 生活服务-评论表
 * @create: 2023-11-06 10:38:12
 **/
@Service("venusProjectServiceCommentService")
@Slf4j
public class VenusProjectServiceCommentService{

    @Resource
    VenusProjectServiceCommentDao venusProjectServiceCommentDao;

    /**
     * 添加生活服务-评论表,获取comment_id数据
     *
     * @param cdoRequest - comment_id:评论id
     *                   - server_id:服务id
     *                   - user_id:评论人id
     *                   - comment_name:评论人
     *                   - comment_content:评论内容
     *                   - comment_parent_id:评论父id
     *                   - create_time:创建时间
     *                   - comment_state:评论状态0.同意1.不同意
     *                   - state:是否删除0.正常1.删除
     * @return
     * @author liuzir
     * @create: 2023-11-06 10:38:12
     */
    @OpenApi
    public Return addVenusProjectServiceComment(CDO cdoRequest) {
        venusProjectServiceCommentDao.addVenusProjectServiceComment(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("comment_id")) {
            cdoResult.set("comment_id", cdoRequest.get("comment_id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据comment_id，更新生活服务-评论表数据
     *
     * @param cdoRequest - comment_id:评论id
     *                   - server_id:服务id
     *                   - user_id:评论人id
     *                   - comment_name:评论人
     *                   - comment_content:评论内容
     *                   - comment_parent_id:评论父id
     *                   - create_time:创建时间
     *                   - comment_state:评论状态0.同意1.不同意
     *                   - state:是否删除0.正常1.删除
     * @return
     * @author liuzir
     * @create: 2023-11-06 10:38:12
     */
    @OpenApi
    public Return updateVenusProjectServiceCommentById(CDO cdoRequest) {
        venusProjectServiceCommentDao.updateVenusProjectServiceCommentById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据comment_id，删除生活服务-评论表数据
     *
     * @param cdoRequest - comment_id:评论id
     * @return
     * @author liuzir
     * @create: 2023-11-06 10:38:12
     */
    @OpenApi
    public Return deleteVenusProjectServiceCommentById(CDO cdoRequest){
        int count = venusProjectServiceCommentDao.deleteVenusProjectServiceCommentById(cdoRequest.getInteger("comment_id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除生活服务-评论表数据
     *
     * @param cdoRequest
     * @return
     * @author liuzir
     * @create: 2023-11-06 10:38:12
     */
    @OpenApi
    public Return deleteVenusProjectServiceComment(CDO cdoRequest) {
        int count = venusProjectServiceCommentDao.deleteVenusProjectServiceComment(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取生活服务-评论表数据
     *
     * @param cdoRequest - comment_id:评论id
     * @return
     * @author liuzir
     * @create: 2023-11-06 10:38:12
     */
    @OpenApi
    public Return getVenusProjectServiceCommentById(CDO cdoRequest) {
        CDO cdoMapperResult = venusProjectServiceCommentDao.getVenusProjectServiceCommentById(cdoRequest.getInteger("comment_id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 评论列表分页
     *
     * @param cdoRequest
     * @return
     * @author liuzir
     * @create: 2023-11-06 10:38:12
     */
    @OpenApi
    public Return getVenusProjectServiceCommentListPage(CDO cdoRequest) {
        int pageIndex = cdoRequest.containsKey("pageIndex") ? cdoRequest.getInteger("pageIndex") : 0;
        int recordSize = cdoRequest.containsKey("recordSize") ? cdoRequest.getInteger("recordSize") : 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusProjectServiceCommentDao.getVenusProjectServiceCommentListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
        int total = venusProjectServiceCommentDao.getVenusProjectServiceCommentCount(cdoRequest);
        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
